package logic

import (
	"context"
	"housing/houserpc/houserpc"

	"housing/api/internal/svc"
	"housing/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddSmsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseAddSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddSmsLogic {
	return &HouseAddSmsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseAddSmsLogic) HouseAddSms(req *types.HouseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	if req.Title == "" || req.Describe == "" || req.Address == "" {
		return &types.Response{
			Message: "必要字段不能为空",
			Code:    500,
			Data:    nil,
		}, nil
	}
	add, err := l.svcCtx.HouseRpc.HouseAdd(l.ctx, &houserpc.HouseAddRequest{
		Title:    req.Title,
		Price:    float32(req.Price),
		Describe: req.Describe,
		Address:  req.Address,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	} else {
		return &types.Response{
			Message: "房源发布成功",
			Code:    200,
			Data:    add,
		}, nil
	}
}
